
#ifndef _FOXTABLE_H_ 
#define _FOXTABLE_H_ 
#include <io.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <string.h> 
#include <sys/stat.h> 
#include <fcntl.h> 
#include <share.h> 
#include <sys/locking.h> 

#ifdef _WINDOWS_ 
#define int16 		short 
#define int32 		int 
#define uint16 		unsigned short 
#define uint32 		unsigned int 
#define bool		short 
#define read		_read 
#define write		_write 
#define sopen		_sopen 
#define close		_close 
#define seek		_seek 
#define locking		_locking 
#define delay		Sleep 
#define SH_DENYRW	_SH_DENYRW 
#define SH_DENYWR	_SH_DENYWR 
#define SH_DENYRD	_SH_DENYRD	 
#define SH_DENYNO	_SH_DENYNO		 
#define S_IWRITE	_S_IWRITE 
#define S_IREAD		_S_IREAD  
#define O_APPEND	_O_APPEND 
#define O_BINARY	_O_BINARY 
#define O_CREAT		_O_CREAT 
#define O_EXCL		_O_EXCL 
#define O_NOINHERIT	_O_NOINHERIT 
#define O_RANDOM	_O_RANDOM 
#define O_RDONLY	_O_RDONLY 
#define O_RDWR		_O_RDWR 
#define O_TEMPORARY	_O_TEMPORARY 
#define O_TEXT		_O_TEXT 
#define O_TRUNC		_O_TRUNC 
#define O_SHORT_LIVED	_O_SHORT_LIVED 
#define O_SEQUENTIAL	_O_SEQUENTIAL 
#define LK_LOCK		_LK_LOCK 
#define LK_RLCK		_LK_RLCK 
#define LK_NBLCK	_LK_NBLCK 
#define LK_NBRLCK	_LK_NBRLCK 
#define LK_UNLCK	_LK_UNLCK 
#else 
#include <dos.h> 
#define int16 		int 
#define int32 		long 
#define uint16 		unsigned int 
#define uint32 		unsigned long 
#define bool		int 
#endif 
#define uchar  	 unsigned char 
#define MAXPATH		256 

#define	errDBFNOFILE 	-101 
#define	errDBFFILEOPEN	-102 
#define	errDBFFILEREAD 	-103 
#define	errDBFFILEWRITE	-104 
#define	errDBFEOFREAD 	-105 
#define	errDBFEOFWRITE 	-106 
#define	errDBFFILELOCK 	-107 
#define errDBFBADHEADER	-108 
#define  LOCK_OFFSET 0x40000000 
typedef struct 
{ 
	uchar	id; 
	char	date[3]; 
	int32	recnum; 
	int16	headlen; 
	int16	reclen; 
	char 	reserved[20]; 
}HEAD; 
typedef struct 
{ 
	char	name[11]; 
	char	type; 
	int16	offset; 
	char	reserved1[2]; 
	uchar	width; 
	uchar	dec; 
	uchar	reserved2[14]; 
}FIELD; 
typedef HEAD* 	LPHEAD; 
typedef FIELD* 	LPFIELD; 

class CDBF 
{ 
public: 
	void alltrim(char *str); 
	void savedata_F(void); 
	int	dbfhdl;							//filehandle 
	BOOL	m_bof,m_eof; 
	int16	fieldscount;					//fields number 
	int32	recno;                  		//current recno 
	LPHEAD 	phead;							//head information 
	LPFIELD pfields;						//field information 
	int16	errorno;						//error no 
	int32	firstpos;						//first record position in file 
	int32	datapos;						//current file position 
	bool	show;							//show deleted record 
	char 	*pdata;							//current record data 
	char	*pBlock; 
	bool	bBlock; 
	char	fname[MAXPATH]; 
	void	loaddata(void);					//read record data from file 
	void 	savedata(void);					//save record data from file 
public: 
	void Post_F(void); 
	int GetLastError(); 
	CDBF(); 
	CDBF(const char *filename); 
	void AssignFile(const char *filename); 
	virtual ~CDBF(void); 
	bool Open(void); 
	void Close(void); 
	int First(void); 
	int Last(void); 
	int Next(void); 
	int Prev(void); 
	int MoveBy(int32 distance); 
	int Go(int32 rec); 
	bool Eof(void); 
	bool Bof(void); 
	char *FieldName(int16 index); 
	int16 FieldIndex(const char *fldname); 
	char *FieldValue(const char *fld); 
	char *FieldValue(int16 index); 
	void Replace(const char *fld,const char *val); 
	void Replace(int16 index,const char *val); 
	void Append(void); 
	void Dele(void); 
	void UnDel(void); 
	bool Deleted(void); 
	void Post(void); 
	bool Exists(); 
	int32 RecordCount(void); 
	int16 FieldsCount(void); 
	int32 RecNo(void); 
	BOOL  BlockRead(void); 
	void  BlockFree(void); 
	void SaveRecord(CString RecBuf); 
	char *ReadRecord(); 
}; 
#ifndef _WINDOWS_ 
#ifdef __cplusplus  
#define min(a,b) ((a>=b)?b:a) 
#define max(a,b) ((a>=b)?a:b) 
#endif 
#endif 
#endif

